class down extends eui.Component implements  eui.UIComponent {
	bitmapresouse:{[index:string]:egret.Bitmap}={}
	movieclickresouse:{[index:string]:egret.MovieClip}={}
	resgroup:eui.Group
	maker:eui.Rect
	scroller:eui.Group
	
	beginhere:boolean=false
	fisttouchpoint:egret.Point
	public constructor() {
		super();
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}


	protected childrenCreated():void
	{
		super.childrenCreated();
		this.scroller.mask=this.maker
        this.fillbackground()
	    this.beginlisten()
	
 
	}
	private addmain(e:egret.TouchEvent)
	{
       CMainEditor.editor.addmedim(e.stageX,e.stageY)
	}
	private touchbegin(e:egret.TouchEvent)
	{ 
	   this.beginhere=true;
	   this.fisttouchpoint=new egret.Point(e.stageX,e.stageY)
	   if(e.target!=this.scroller&&e.target!=this.resgroup)
	   {
		  if(e.target.texture!=undefined)
		   CMainEditor.editor.addnewbitmapOBJECTtostage(e.target.texture,e.stageX,e.stageY,e.target.name)
		   else
		   CMainEditor.editor.addnewmovieclickOBJECTtostage(e.target.name,e.stageX,e.stageY,e.target.name+"/json")
	   }
	   
	}
	private tonchend(e:egret.TouchEvent)
	{
		this.beginhere=false;
	}
	private touchmove(e:egret.TouchEvent)
	{
		if(this.beginhere)
		{
		  
          let nowpoint=new egret.Point(e.stageX,e.stageY);
		  let vector=this.fisttouchpoint.subtract(nowpoint);
	      if(vector.y>0&&this.checkend())return
		  else if(vector.y<0&&this.resgroup.y>=0)return
		  this.resgroup.y-=vector.y;
		  this.fisttouchpoint=nowpoint
	
		}

	}
	private checkend():boolean
	{
		let stagepoint=this.scroller.localToGlobal(0,0)
        let local=this.resgroup.globalToLocal(stagepoint.x,stagepoint.y)
	
		if((local.y+this.height)>=this.resgroup.height)return true;
		else return false;

	}
	
	public readjason(json:ResourceInfo[]):void
	{
		
	   let nowx:number=20
	   let nowy:number=20
	   let cheak:boolean=false
       for(let a=0;a<json.length;a++)
	   {
		 
		 
		   let name=json[a].name
		    if(name=="description_json")
			{
				cheak=true;
				continue
			}
			if(cheak)
			{
				let bitmap;
			   if(name.split("_")[1]=="json")
			   {
				  let aname=name.split("_")[0];
				  bitmap=this.createMovieClipByJsonAndName(aname+"_json",aname+"_png")
                  bitmap.name=aname;
				  this.movieclickresouse[name]=bitmap
			   }
			   else 
			   {
                  bitmap=this.createBitmapByName(name)
				  bitmap.name=name;
				 this.bitmapresouse[name]=bitmap
			   }
		       
			   bitmap.scaleX=((this.width-20*6)/10)/bitmap.width
		       bitmap.scaleY=(this.height-40)/bitmap.height
		       
		 
		       this.resgroup.addChild(bitmap)
		       bitmap.touchEnabled=true
		  
		   if((nowx+bitmap.width*bitmap.scaleX+20)>this.resgroup.width)
		   {
			   nowx=20
			   nowy+=this.height+20
			 
		   }
		   bitmap.x=nowx;
		   bitmap.y=nowy;
		   nowx+=bitmap.width*bitmap.scaleX+20
		 
		   
			}
		
			
			
	   }
	 
			this.resgroup.height+=nowy
			
	   
	   
	}
	private fillbackground()
	{
		let shape=new egret.Shape
		shape.graphics.beginFill(0xADD8E6,0.8)
		
		shape.graphics.drawRect(0,0,this.resgroup.width,this.resgroup.height)
		shape.graphics.endFill()
		this.scroller.addChildAt(shape,0)
		shape.x=0,shape.y=0
	}
	protected createBitmapByName(name: string):egret.Bitmap{
		var bitmap=new egret.Bitmap()
        let a: egret.Texture= RES.getRes(name);
		bitmap.texture = a;
		return bitmap; 
		
    }
	protected createMovieClipByJsonAndName(stjson:string,strpng:string):egret.MovieClip
	{
		var _json=RES.getRes(stjson);
		var _png=RES.getRes(strpng);		
		var MovieClipDataFactory=new egret.MovieClipDataFactory(_json,_png);
		return (new egret.MovieClip(MovieClipDataFactory.generateMovieClipData()));
	}
	public beginlisten()
	{
		this.scroller.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchmove,this);
		this.scroller.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchbegin,this);
		this.scroller.addEventListener(egret.TouchEvent.TOUCH_END,this.tonchend,this);
		this.scroller.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.addmain,this);
	}
	public stoplisten()
	{
		this.scroller.removeEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchmove,this);
		this.scroller.removeEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchbegin,this);
		this.scroller.removeEventListener(egret.TouchEvent.TOUCH_END,this.tonchend,this);
		this.scroller.removeEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.addmain,this);
	}
}